package udp_tcp.model;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Message {
    private User sender;
    private String content;
    private LocalDateTime timestamp;

    public Message(User sender, String content) {
        this.sender = sender;
        this.content = content;
        this.timestamp = LocalDateTime.now();
    }

    // Getters
    public User getSender() { return sender; }
    public String getContent() { return content; }
    public String getTimestamp() {
        return timestamp.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
    }

    @Override
    public String toString() {
        return String.format("[%s] %s: %s",
                getTimestamp(), sender.getUsername(), content);
    }
}